﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using NHibernate;

using FluentNHibernate.Automapping;
using FluentNHibernate.Automapping.Alterations;

namespace Domain.Model.Mapping.Overrides
{
    public class ProjectMappingOverride : IAutoMappingOverride<Project>
    {
        public void Override(AutoMapping<Project> mapping)
        {
            mapping.References<Program>(x => x.Program)
                .Column("ProgramId").Nullable();

            mapping.HasMany<Subproject>(x => x.Subprojects)
                .Cascade.All()
                .Inverse()
                .Not.LazyLoad()
                .AsBag();

            mapping.HasMany<ProjectTask>(x => x.Tasks)
                .Cascade.All()
                .Inverse()
                .Not.LazyLoad()
                .AsBag();

            mapping.HasMany<ProjectDetail>(x => x.Details)
                .Cascade.All()
                .Inverse()
                .Not.LazyLoad()
                .AsBag();

            mapping.References<ProjectStatus>(x => x.Status)
                .Cascade.All()
                .Not.LazyLoad();
        }
    }
}